﻿class Game extends PqGame {
    private speed: number = 2;
    private fx:number=0.1;
    public constructor() {
        super();
        this.btnNameList.push("img0");
        this.funcList.push(this.func0);
        this.btnNameList.push("img1");
        this.funcList.push(this.func1);
        this.btnNameList.push("img2");
        this.funcList.push(this.func2);
        this.target = this;
    }
    protected execute() {
        this.ui = new View();
        this.addChild(this.ui);
        this.registerEvent();
        this.ui.uiDict["img3"].alpha = 0.5;
        this.ui.uiDict["img3"].addEventListener(egret.Event.ENTER_FRAME, this.autoMove, this);
    }
    private autoMove(e: egret.Event) {
        e.target.x += this.speed * this.fx;
        e.target.y += this.speed * (0 - this.fx);
        this.speed += 0.2*this.fx;
        if (this.speed >= 5) this.fx = -1;
        else if (this.speed <= 0) this.fx = 1;
    }
    private func0(type: string, e: any) {
        e.target.x += Math.random() * 100 - 50;
        e.target.y += Math.random() * 100 - 50;
    }
    private func1(type: string, e: any) {
        e.target.x += Math.random() * 100 - 50;
        e.target.y += Math.random() * 100 - 50;
    }
    private func2(type: string, e: any) {
        e.target.x += Math.random() * 100 - 50;
        e.target.y += Math.random() * 100 - 50;
    }
    protected gameClick(e: egret.TouchEvent): void {
        EventHelper.send(e, this.btnNameList, this.funcList, this.target);
    }
}